<?php
/**
 * Created by Zend Studio.
 * User: FDG367
 * @param  FDG367 2018-03-20  542 【商城需求】心愿单界面增加预约到店功能，点击预约到店，新增页面填写用户信息 start
 * Date: 2018/03/20
 * Time: 11:36
 */
namespace common\models;

use common\helps\tools;
use yii\db\ActiveRecord;

class ShareWishReserv extends ActiveRecord{
    public static function tableName(){
        return '{{%share_wish_reserv}}';
    }
	const ADDRESS_TYPE_ONE	=1;//闵行店
	const ADDRESS_TYPE_TWO	=2;//浦东店

	const USE_FLG_YES	=1;//处理状态已处理
	const USE_FLG_NO	=0;//处理状态未处理

	const RESERV_TIME_EX_ONE	=1;//1:上午（10:00-12:00）
	const RESERV_TIME_EX_TWO	=2;//2:下午（12:00-18:00）
	const RESERV_TIME_EX_THR	=3;//3：晚上（18:00-20:00）

	public static  $address_arr=[
		self::ADDRESS_TYPE_ONE=>'上海，吴中路1265号',
		self::ADDRESS_TYPE_TWO=>'上海，东方路1833号',

	];

	public static  $reserv_arr=[
		self::RESERV_TIME_EX_ONE=>'上午（10:00-12:00）',
		self::RESERV_TIME_EX_TWO=>'下午（12:00-18:00）',
		self::RESERV_TIME_EX_THR=>'晚上（18:00-20:00）',
	];

	public function rules(){
		return [
			[['wish_list_id','reserv_name','reserv_mobile','cust_member_no','use_flg','cust_id','cust_mobile','address_type','reserv_time','reserv_time_ex','create_time'],'safe'],
			[['reserv_mobile'],'match','pattern'=>'/^\d{11}$|\d{3}-\d{8}|\d{4}-\d{7,8}/'],
			[['reserv_name','reserv_mobile'],'required','message'=>'必填'],
		];
	}

	public function saveInfo($data){
		$this->load($data,'');

		if(!$this->save()){
			return false;
		}
		return $this;
	}

	public function beforeSave($insert){
		$master_info 	= \common\helps\tools::getloginMasterInfo();
		$this->create_time  	= date('Y-m-d H:i:s');
		$this->cust_id  		= $master_info->id;
		$this->cust_member_no  	= $master_info->member_no;
		$this->cust_mobile  	= $master_info->mobile;
		$this->use_flg  		= self::USE_FLG_NO;
		return true;
	}

}